#include <catch2/catch.hpp>

#include <array>

#include "solution.hpp"

using namespace solution_086;

TEST_CASE("86. Partition List", "[086]") {

    SECTION("example 1") {
        std::array n{ ListNode(1), ListNode(4), ListNode(3), ListNode(2), ListNode(5), ListNode(2) };
        for (size_t i = 0, j = 1; j < n.size(); ++i, ++j)
            n[i].next = &n[j];
        auto node = Solution().partition(&n[0], 3);
        for (auto v : {1,2,2,4,3,5}) {
            CHECK(node->val == v);
            node = node->next;
        }
    }

    SECTION("example 2") {
        std::array n{ ListNode(2), ListNode(1) };
        for (size_t i = 0, j = 1; j < n.size(); ++i, ++j)
            n[i].next = &n[j];
        auto node = Solution().partition(&n[0], 2);
        for (auto v : {1,2}) {
            CHECK(node->val == v);
            node = node->next;
        }
    }
}
